home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jumping_jelly_beans.swf / scripts / frame_10 / DoAction.as
Text File  |  2006-11-29  |  11KB  |  509 lines

  1. MovieClip.prototype.make = function(tipe, x)
  2. {
  3.    if(!x)
  4.    {
  5.       x = 620;
  6.    }
  7.    if(!tipe)
  8.    {
  9.       m.attachmovie("ff","a" + r.ad,r.ad);
  10.       m["a" + r.ad]._x = x;
  11.       var op = 0;
  12.       if(r.ypos.length > 1)
  13.       {
  14.          if(random(100) > 50)
  15.          {
  16.             var op = 1;
  17.          }
  18.       }
  19.       m["a" + r.ad]._y = r.ypos[op];
  20.    }
  21.    else if(tipe == 2)
  22.    {
  23.       m.attachmovie("fire","a" + r.ad,r.ad);
  24.       m["a" + r.ad]._x = 630;
  25.       m["a" + r.ad]._y = 390;
  26.    }
  27.    else if(tipe == 9)
  28.    {
  29.       m.attachmovie("bonus","bonus" + r.ad,r.ad);
  30.       m["bonus" + r.ad]._x = 630;
  31.       m["bonus" + r.ad]._y = r.ypos[0];
  32.       var tp = 1;
  33.       if(r.timepassed < 3000)
  34.       {
  35.          if(r.time > 0.8 * r.timemax)
  36.          {
  37.             if(random(100) < 70)
  38.             {
  39.                tp = 2;
  40.             }
  41.          }
  42.       }
  43.       else if(random(100) < 70)
  44.       {
  45.          tp = 2;
  46.       }
  47.       m["bonus" + r.ad].tipe = tp;
  48.    }
  49.    r.ad = r.ad + 1;
  50. };
  51. MovieClip.prototype.flick = function()
  52. {
  53.    var t = this;
  54.    t.onEnterFrame = function()
  55.    {
  56.       t._alpha = 70 + random(30);
  57.    };
  58. };
  59. MovieClip.prototype.run = function()
  60. {
  61.    var t = this;
  62.    t.no = Number(t._name.substr(2,1));
  63.    t.onEnterFrame = function()
  64.    {
  65.       t._x = m["sh" + t.no]._x = r.xpos[t.no] + (t._x - r.xpos[t.no]) / 1.1;
  66.       if(t.hit)
  67.       {
  68.          delete t.onEnterFrame;
  69.          t.gotoAndPlay("hitt");
  70.       }
  71.       else if(r.pres == t.no)
  72.       {
  73.          delete t.onEnterFrame;
  74.          t.gotoAndPlay("follow");
  75.       }
  76.       t.cekinv();
  77.    };
  78.    t.stop();
  79. };
  80. MovieClip.prototype.follow = function()
  81. {
  82.    var t = this;
  83.    t.swapDep(r.pd);
  84.    t.onEnterFrame = function()
  85.    {
  86.       t.nx = r._xmouse;
  87.       t.ceklimits();
  88.       t._x = m["sh" + t.no]._x = t.nx + (t._x - t.nx) / 1.4;
  89.       if(t.hit)
  90.       {
  91.          delete t.onEnterFrame;
  92.          t.gotoAndPlay("hitt");
  93.       }
  94.       else if(!r.pres)
  95.       {
  96.          delete t.onEnterFrame;
  97.          t.gotoAndPlay("jump");
  98.       }
  99.       t.cekinv();
  100.    };
  101.    t.stop();
  102. };
  103. MovieClip.prototype.cekhitob = function()
  104. {
  105.    var n = 1;
  106.    while(n <= 3)
  107.    {
  108.       if(!r.jump[n])
  109.       {
  110.          var t = m["p" + n];
  111.          if(!t.hit and t.inv <= 0)
  112.          {
  113.             if(t.z2.hitTest(this.z))
  114.             {
  115.                t.hit = 1;
  116.             }
  117.          }
  118.       }
  119.       n++;
  120.    }
  121. };
  122. MovieClip.prototype.cekgot = function()
  123. {
  124.    var res = 0;
  125.    var n = 1;
  126.    while(n <= 3)
  127.    {
  128.       if(r.jump[n])
  129.       {
  130.          var t = m["p" + n];
  131.          if(t.c > r.minc[n] and t.c < r.maxc[n])
  132.          {
  133.             if(t.p.arm.net.z.hitTest(this._x,this._y,1))
  134.             {
  135.                t.got = t.got + 1;
  136.                r.got = r.got + 1;
  137.                t.xgot = this._x;
  138.                res = t;
  139.                break;
  140.             }
  141.          }
  142.       }
  143.       n++;
  144.    }
  145.    return res;
  146. };
  147. MovieClip.prototype.cekinv = function()
  148. {
  149.    var t = this;
  150.    t.clr = new color(t);
  151.    if(t.inv > 0)
  152.    {
  153.       t.inv--;
  154.       t._visible = !t._visible;
  155.       if(!t.inv)
  156.       {
  157.          t.clr.resetcolor();
  158.       }
  159.    }
  160.    else
  161.    {
  162.       t._visible = 1;
  163.    }
  164. };
  165. MovieClip.prototype.hitt = function()
  166. {
  167.    var t = this;
  168.    t._y = r.yland - 8;
  169.    r.time = Math.max(0,r.time - r.timehit);
  170.    r.timebar.frame.play();
  171.    t.ys = -20;
  172.    t.gra = 10;
  173.    r.zhit.start();
  174.    t.onEnterFrame = function()
  175.    {
  176.       t._y += t.ys;
  177.       t.ys += t.gra;
  178.       if(t._y >= r.yland)
  179.       {
  180.          t._y = r.yland;
  181.          delete t.onEnterFrame;
  182.          t.inv = r.invhitdelay;
  183.          t.clr = new color(t);
  184.          t.clr.setBrightness(20);
  185.          t.hit = 0;
  186.          t.gotoAndPlay("run");
  187.       }
  188.    };
  189.    t.stop();
  190. };
  191. MovieClip.prototype.jump = function()
  192. {
  193.    var t = this;
  194.    t.ys = r.jumppower[t.no];
  195.    r.jump[t.no] = 1;
  196.    t.c = 1;
  197.    t.uda = 0;
  198.    t.got = 0;
  199.    t.onEnterFrame = function()
  200.    {
  201.       t.cekinv();
  202.       t.c = t.c + 1;
  203.       if(t.c == r.maxc[t.no] + 4)
  204.       {
  205.          if(t.got > 1)
  206.          {
  207.             showgot(t.got,t.no,t.xgot - 20,t.tipenet);
  208.          }
  209.       }
  210.       t._y += t.ys;
  211.       t.ys += r.grav[t.no];
  212.       if(t.ys > 1)
  213.       {
  214.          if(!t.uda)
  215.          {
  216.             t.uda = 1;
  217.             r.xpos[t.no] = t._x;
  218.             var allpos = [];
  219.             var f = 0;
  220.             while(f < 3)
  221.             {
  222.                allpos.push({no:f + 1,x:r.xpos[f + 1]});
  223.                f++;
  224.             }
  225.             allpos.sortBy("x");
  226.             var f = 0;
  227.             while(f < 3)
  228.             {
  229.                if(allpos[f].no == t.no)
  230.                {
  231.                   var startno = f;
  232.                }
  233.                f++;
  234.             }
  235.             if(startno < 2)
  236.             {
  237.                var f = startno + 1;
  238.                while(f < 3)
  239.                {
  240.                   if(allpos[f].x - t._x < r.spacing)
  241.                   {
  242.                      var nx = Math.min(t._x + r.spacing,r.xmax);
  243.                      allpos[f].x = r.xpos[allpos[f].no] = nx;
  244.                   }
  245.                   f++;
  246.                }
  247.             }
  248.             if(startno > 0)
  249.             {
  250.                var f = startno - 1;
  251.                while(f >= 0)
  252.                {
  253.                   if(t._x - allpos[f].x < r.spacing)
  254.                   {
  255.                      var nx = Math.max(t._x - r.spacing,r.xmin);
  256.                      allpos[f].x = r.xpos[allpos[f].no] = nx;
  257.                   }
  258.                   f--;
  259.                }
  260.             }
  261.          }
  262.          if(t._y >= r.yland)
  263.          {
  264.             t._y = r.yland;
  265.             r.jump[t.no] = 0;
  266.             t.swapDep(r.pd2);
  267.             delete t.onEnterFrame;
  268.             t.gotoAndPlay("run");
  269.          }
  270.       }
  271.    };
  272.    t.stop();
  273. };
  274. MovieClip.prototype.showgot = function(got, no, x, tipenet)
  275. {
  276.    m.attachMovie("got","got" + r.ad,r.ad);
  277.    m["got" + r.ad]._x = x;
  278.    m["got" + r.ad]._y = r.yposnormal[no - 1];
  279.    m["got" + r.ad].got = got;
  280.    m["got" + r.ad].tipenet = tipenet;
  281.    r.ad = r.ad + 1;
  282. };
  283. MovieClip.prototype.swapDep = function(d)
  284. {
  285.    this.swapDepths(d);
  286.    this.dep = d;
  287. };
  288. MovieClip.prototype.initz = function()
  289. {
  290.    this._visible = 0;
  291. };
  292. movieclip.prototype.ceklimits = function()
  293. {
  294.    this.nx = Math.max(this.nx,r.xmin);
  295.    this.nx = Math.min(this.nx,r.xmax);
  296. };
  297. MovieClip.prototype.jiggle = function(beginska, dv, dvstep)
  298. {
  299.    var t = this;
  300.    if(!beginska)
  301.    {
  302.       beginska = 150;
  303.    }
  304.    t._xscale = t._yscale = beginska;
  305.    t.ska = 100;
  306.    t.dx = 0;
  307.    t.dy = 0;
  308.    if(!dv)
  309.    {
  310.       t.dv = 0.9;
  311.    }
  312.    else
  313.    {
  314.       t.dv = dv;
  315.    }
  316.    if(!dvstep)
  317.    {
  318.       t.dvstep = 0.5;
  319.    }
  320.    else
  321.    {
  322.       t.dvstep = dvstep;
  323.    }
  324.    t.onenterframe = function()
  325.    {
  326.       t.dx = t.dx * t.dvstep + (t.ska - t._xscale) * t.dv;
  327.       t.dy = t.dy * t.dvstep + (t.ska - t._yscale) * t.dv;
  328.       t._xscale += t.dx;
  329.       t._yscale += t.dy * 1.5;
  330.    };
  331. };
  332. Array.prototype.removeElement = function(i)
  333. {
  334.    if(i == null)
  335.    {
  336.       i = 0;
  337.    }
  338.    var r = this[i];
  339.    var j = i;
  340.    while(j < this.length - 1)
  341.    {
  342.       this[j] = this[j + 1];
  343.       j++;
  344.    }
  345.    this.pop();
  346.    return r;
  347. };
  348. Array.prototype.removeValue = function(a)
  349. {
  350.    var i = 0;
  351.    while(i < this.length)
  352.    {
  353.       if(a == this[i])
  354.       {
  355.          this.removeElement(i);
  356.       }
  357.       i++;
  358.    }
  359. };
  360. Array.prototype.randomize = function()
  361. {
  362.    return this.sort(function(a, b)
  363.    {
  364.       return Math.floor(Math.random() * 2) != 0 ? -1 : 1;
  365.    }
  366.    );
  367. };
  368. Array.prototype.copy = Array.prototype.slice;
  369. Movieclip.prototype.fadescreen = function(speed)
  370. {
  371.    if(!speed)
  372.    {
  373.       var speed = 5;
  374.    }
  375.    _root.createEmptyMovieClip("dark",100001);
  376.    var d = _root.dark;
  377.    with(d)
  378.    {
  379.       lineStyle(1,0,100);
  380.       beginfill(0,100);
  381.       moveto(-5000,-5000);
  382.       lineto(5000,-5000);
  383.       lineto(5000,5000);
  384.       lineto(-5000,5000);
  385.       endfill();
  386.       d.onEnterFrame = function()
  387.       {
  388.          _alpha -= speed;
  389.          if(_alpha <= 0)
  390.          {
  391.             removeMovieClip("");
  392.             stop();
  393.          }
  394.       };
  395.    }
  396. };
  397. Array.prototype.sortBy = function(key)
  398. {
  399.    var comparisonFunction = function(a, b)
  400.    {
  401.       var aTemp = typeof a[key] != "string" ? a[key] : a[key].toLowerCase();
  402.       var bTemp = typeof b[key] != "string" ? b[key] : b[key].toLowerCase();
  403.       if(aTemp < bTemp)
  404.       {
  405.          return -1;
  406.       }
  407.       if(aTemp > bTemp)
  408.       {
  409.          return 1;
  410.       }
  411.       return 0;
  412.    };
  413.    this.sort(comparisonFunction);
  414. };
  415. Movieclip.prototype.findang = function(dx, dy)
  416. {
  417.    return deg(math.atan2(dy,dx));
  418. };
  419. Movieclip.prototype.rad = function(qdeg)
  420. {
  421.    return qdeg * 0.017453292519943295;
  422. };
  423. Movieclip.prototype.deg = function(qrad)
  424. {
  425.    return qrad * 57.29577951308232;
  426. };
  427. Color.prototype.setBrightness = function(value)
  428. {
  429.    this.setTransform({ra:100,rb:0,ga:100,gb:0,ba:100,bb:0});
  430.    var trans = this.getTransform();
  431.    var percent = Math.abs(value) / 100;
  432.    var brightnessColor = value <= 0 ? 0 : 255;
  433.    with(trans)
  434.    {
  435.       ra -= ra * percent;
  436.       ga -= ga * percent;
  437.       ba -= ba * percent;
  438.       rb += (brightnessColor - rb) * percent;
  439.       gb += (brightnessColor - gb) * percent;
  440.       bb += (brightnessColor - bb) * percent;
  441.    }
  442.    this.setTransform(trans);
  443. };
  444. Color.prototype.resetcolor = function()
  445. {
  446.    this.setTransform({ra:100,rb:0,ga:100,gb:0,ba:100,bb:0});
  447. };
  448. Sound.prototype.fade = function(fadeType, fadeDuration)
  449. {
  450.    this.fadeDuration = fadeDuration * 1000 / 100;
  451.    this.fadeType = fadeType;
  452.    this.currentVolume = this.getVolume();
  453.    this.intID = setInterval(function(thisObj)
  454.    {
  455.       thisObj.doFade(thisObj.fadeType);
  456.    }
  457.    ,this.fadeDuration,this);
  458.    this.doFade = function(fadeType)
  459.    {
  460.       if(fadeType == "out")
  461.       {
  462.          this.setVolume(this.currentVolume--);
  463.          if(this.getVolume() <= 0)
  464.          {
  465.             clearInterval(this.intID);
  466.          }
  467.       }
  468.       else if(fadetype == "in")
  469.       {
  470.          this.setVolume(this.currentVolume++);
  471.          if(this.getVolume() >= 100)
  472.          {
  473.             clearInterval(this.intID);
  474.          }
  475.       }
  476.    };
  477. };
  478. movieclip.prototype.wait = function(delay)
  479. {
  480.    this.createEmptyMovieClip("wdl",55555);
  481.    this.wdl.delay = delay;
  482.    this.wdl.onenterframe = function()
  483.    {
  484.       this.delay--;
  485.       if(!this.delay)
  486.       {
  487.          delete this.onenterframe;
  488.          this._parent.play();
  489.          this.removeMovieClip();
  490.       }
  491.    };
  492.    this.stop();
  493. };
  494. MovieClip.prototype.savecookie = function(vari, value)
  495. {
  496.    var so = SharedObject.getLocal("lazcookie","/");
  497.    so.data[vari] = value;
  498.    so.flush();
  499. };
  500. MovieClip.prototype.loadcookie = function(vari)
  501. {
  502.    var so = SharedObject.getLocal("lazcookie","/");
  503.    if(so.data[vari] != null)
  504.    {
  505.       return so.data[vari];
  506.    }
  507.    return false;
  508. };
  509.